package com.test.ayi.test.competablefuture;

import java.util.concurrent.CompletableFuture;

public class CFtestSupplyAsync {
    public static void main(String[] args) throws InterruptedException {
        long submitTs = System.nanoTime();

        CompletableFuture<String> takeout = CompletableFuture.supplyAsync(() -> {
            // 任务真正开始执行的时间点
            long startTs = System.nanoTime();

            // 计算并打印调度延迟（毫秒）
            long latencyMs = (startTs - submitTs) / 1_000_000;
            System.out.printf("调度延迟：%d ms%n", latencyMs);

            // 业务流程
            try {
                Thread.sleep(5000);
            } catch (InterruptedException ignored) {
            }
            return "麻辣小龙虾";
        });

        System.out.println("我先刷剧...");
        System.out.println("结果：" + takeout.join());

    }
}
